package com.gome.boot.config.datasource.single;

import com.gome.boot.config.datasource.BaseDataSourceConfig;
import com.gome.boot.config.datasource.IDataSourceTransactionConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

/**
 * 单数据源配置.
 *
 * @author baoxiufeng
 */
public abstract class SingleDataSourceConfig extends BaseDataSourceConfig implements IDataSourceTransactionConfig {

    @Bean(initMethod = "init", destroyMethod = "close")
    public DataSource dataSource() throws Exception {
        return getSingleDataSource();
    }

    /**
     * 获取指定数据源.
     *
     * @return 数据源对象
     * @throws Exception 异常
     */
    protected abstract DataSource getSingleDataSource() throws Exception;

    @Override
    public DataSourceTransactionManager transactionManager() throws Exception {
        return null;
    }
}
